﻿using System.Web.Mvc;
using VideoSeller.Business.Models;
using VideoSeller.Web.Models;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web.Helpers;

namespace VideoSeller.Web.Controllers
{
	[Authorize(Roles = "Administrator, Moderator")]
	public class StatisticController : BaseController
	{
		private readonly StatisticModel _statisticModel;

		public StatisticController(StatisticModel statisticModel)
		{
			_statisticModel = statisticModel;
		}

		[HttpGet]
		public ViewResult OnlineNow()
		{
			var model = new StatisticOnlineNowViewModel();
			model.Items = _statisticModel.GetOnlineStatistic();
			return View(model);
		}

		[HttpGet]
		public ViewResult OnlinePeriod()
		{
			var model = new StatisticOnlinePeriodViewModel();
			model.Items = _statisticModel.GetOnlineStatistic();
			return View(model);
		}

		[HttpPost]
		public ViewResult OnlinePeriod(StatisticOnlinePeriodViewModel model)
		{
			model.Items = _statisticModel.GetOnlineStatistic(model.StartDateTime, model.EndDateTime);
			return View(model);
		}
        //[HttpPost]
        //public ViewResult VSMChartPeriod()
        //{
        //    var model = new VSMChartPeriodViewModel();
        //    return View(model);
        //}
        [HttpGet]
        public ActionResult dimage()
        {
            var chart = new Chart(width: 300, height: 200)
               .AddSeries(
                           chartType: "line",
                           xValue: new[] { 1, 2, 3, 4 },
                           yValues: new[] { 100, 200, 3000, 400 })
                           .GetBytes("png");
            return File(chart, "image/bytes");
        }
	}
}